package com.angel.email;

import org.junit.Test;

import com.angel.email.account.AccountInformation;
import com.angel.email.account.impl.MockAccountInformation;
import com.angel.email.configuration.EmailConfiguration;
import com.angel.email.configuration.builders.EmailConfigurationBuilder;
import com.angel.email.configuration.builders.impl.google.GoogleIncomingEmailConfigurationBuilder;
import com.angel.email.configuration.builders.impl.yahoo.YahooIncomingEmailConfigurationBuilder;
import com.angel.email.connection.IncomingEmailConnection;
import com.angel.email.dtos.FolderDTO;
import com.angel.email.response.EmailMessagesResponse;

/**
 *
 * @author William
 *
 */
public class IncomingEmailTestCase {

	@Test
	public void testIncomingYahooInbox(){
		AccountInformation accountInfo = new MockAccountInformation("guillesalazar1983@yahoo.com.ar", "GUILLE1983");
		EmailConfigurationBuilder ecb = new EmailConfigurationBuilder(Boolean.FALSE);
		ecb.setIncomingConfigurationBuilder(new YahooIncomingEmailConfigurationBuilder(accountInfo));
		EmailConfiguration emailConfiguration = ecb.buildEmailConfiguration();
		IncomingEmailConnection emailConnection = emailConfiguration.connectToIncomingEmail();
		FolderDTO folder = emailConnection.getFolderFor("INBOX");
		EmailMessagesResponse messages = emailConnection.getMessagesForFolder("INBOX", 10);
		folder.getMessageCount();
		messages.getTotalSize();
		emailConnection.closeConnection();
	}

	@Test
	public void testIncomingGoogleInbox(){
		AccountInformation accountInfo = new MockAccountInformation("guillesalazar@gmail.com", "42416467");
		EmailConfigurationBuilder ecb = new EmailConfigurationBuilder(Boolean.FALSE);
		ecb.setIncomingConfigurationBuilder(new GoogleIncomingEmailConfigurationBuilder(accountInfo));
		EmailConfiguration emailConfiguration = ecb.buildEmailConfiguration();
		IncomingEmailConnection emailConnection = emailConfiguration.connectToIncomingEmail();
		FolderDTO folder = emailConnection.getFolderFor("INBOX");
		EmailMessagesResponse messages = emailConnection.getMessagesForFolder("INBOX", 10);
		folder.getMessageCount();
		messages.getTotalSize();
		emailConnection.closeConnection();
	}
}
